#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(register int i = (x); i <= (y); i++) 
#define per(i, x, y) for(register int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 4e5 + 10;
const int B = 650;

int xl[N], xr[N], bel[N], anc[N], mt[N], tg[N];
int n, m, fa[N], lstans;

inline void upd(const int &x) { if(mt[bel[x]] <= B) anc[x] = bel[fa[x]] == bel[x] ? anc[fa[x]] : fa[x]; }
inline int getfa(const int &x) { return mt[bel[x]] > B ? max(fa[x] - tg[bel[x]], 1) : fa[x]; }
inline int getanc(const int &x) { return mt[bel[x]] > B ? max(fa[x] - tg[bel[x]], 1) : anc[x]; }

inline void tmodify(const int &id, const int &v) {
	if(mt[id] > B) return tg[id] = min(v + tg[id], n), void();
	rep(i, xl[id], xr[id]) fa[i] = max(1, fa[i] - v), upd(i);
}

inline void modify(const int &l, const int &r, const int &v) {
	int bl = bel[l], br = bel[r];
	if(bl == br) {
		rep(i, l, r) fa[i] = max(1, fa[i] - v);
		rep(i, l, xr[bl]) upd(i);
	} else {
		rep(i, l, xr[bl]) fa[i] = max(1, fa[i] - v), upd(i);
		rep(i, bl + 1, br - 1) tmodify(i, v), mt[i]++;
		rep(i, xl[br], r) fa[i] = max(1, fa[i] - v);
		rep(i, xl[br], xr[br]) upd(i);
	}
}

inline int lca(const int &x, const int &y) {
	if(x == y) return x; register int fx = getanc(x), fy = getanc(y);
	if(bel[fx] ^ bel[fy]) return bel[fx] < bel[fy] ? lca(x, fy) : lca(fx, y);
	if(fx ^ fy) return fx < fy ? lca(x, fy) : lca(fx, y);
	return x < y ? lca(x, getfa(y)) : lca(getfa(x), y);
}

int ans;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 1, n) bel[i] = (i - 1) / B + 1, (xl[bel[i]] == 0) && (xl[bel[i]] = i), xr[bel[i]] = i;	
	rep(i, 2, n) fa[i] = in, upd(i);
	rep(i, 1, m) {
		int op = in, l, r, x;
		if(op == 1) {
			l = in, r = in, x = in;
			l ^= ans; r ^= ans; x ^= ans;
			modify(l, r, x);
		} else l = in, r = in, l ^= ans, r ^= ans, ans = lca(l, r), printf("%d\n", ans);
	}
	return 0;
}
